import urllib.request
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
url = 'http://www.baidu.com'

headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
}

request = urllib.request.Request(url=url, headers=headers)

# handler   build_opener    open

# 设置代理ip
proxies = {
    "http": "183.236.123.242:8060"
}

# 获取handler对象
handler = urllib.request.ProxyHandler(proxies=proxies)

# 获取opener对象
opener = urllib.request.build_opener(handler)

# 调用 opener对象
req = opener.open(request)
content = req.read().decode('utf-8')
print(content)
